package com.gp.learn.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gp.learn.common.core.mybaitsplus.ResultInfo;
import com.gp.learn.common.core.mybaitsplus.conditions.SuperQueryWrapper;
import com.gp.learn.web.entity.Dept;
import com.gp.learn.web.entity.User;
import com.gp.learn.web.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("getUserInfoList")
    public ResultInfo selectListMap() {
        SuperQueryWrapper<User> qw = new SuperQueryWrapper<>(User.class);
        qw.select(User.class, "id", "name", "age", "email");
        qw.select(Dept.class, "deptId", "deptName");
        qw.createJoin(Dept.class).setMainClass(User.class).setMainField("deptId").setJonClass(Dept.class).setJoinField("deptId");
        List<Map<String, Object>> data = userService.selectListMap(qw);
        return ResultInfo.ok(data);
    }

    @RequestMapping("testPageList")
    public ResultInfo testPageList() {
        SuperQueryWrapper<User> qw = new SuperQueryWrapper<>(User.class);
        qw.select(Dept.class, "deptId", "deptName");
        qw.select(User.class, "id", "name", "age", "email");
        qw.createJoin(Dept.class).setMainClass(User.class).setMainField("deptId").setJonClass(Dept.class).setJoinField("deptId");
        Page<User> page = new Page<>(1, 1);
        Page<Map<String, Object>> data = (Page<Map<String, Object>>) userService.pageList(page, qw);
        return ResultInfo.ok(data);
    }
}
